package com.czmh.etc.onlinepubsys.services.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.czmh.etc.onlinepubsys.dto.CmsQueryContentCategoryParam;
import com.czmh.etc.onlinepubsys.maper.CmsContentCategoryMapper;
import com.czmh.etc.onlinepubsys.model.CmsContentCategory;
import com.czmh.etc.onlinepubsys.services.CmsContentCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 资讯分类表 服务实现类
 * </p>
 *
 * @author eric
 * @since 2021-06-07
 */
@Service
public class CmsContentCategoryServiceImpl extends ServiceImpl<CmsContentCategoryMapper, CmsContentCategory> implements CmsContentCategoryService {
    @Autowired
    CmsContentCategoryMapper cmsContentCategoryMapper;

    @Override
    public IPage<CmsContentCategory> queryList(Integer pageSize, Integer pageNum) {
        Page<CmsContentCategory> page = new Page<>(pageNum,pageSize);
        QueryWrapper<CmsContentCategory> wrapper = new QueryWrapper<>();
        LambdaQueryWrapper<CmsContentCategory> lambda = wrapper.lambda();
        lambda.eq(CmsContentCategory::getDeleteFlag, 0);
        lambda.eq(CmsContentCategory::getShowStatus, 1);
        lambda.orderByDesc(CmsContentCategory::getSort);
        return page(page, wrapper);
    }


    @Override
    public IPage<CmsContentCategory> queryList(CmsQueryContentCategoryParam queryParam, Integer pageSize, Integer pageNum) {
        IPage<CmsContentCategory> page = new Page<>(pageNum, pageSize);
        QueryWrapper<CmsContentCategory> wrapper = new QueryWrapper<>();
        LambdaQueryWrapper<CmsContentCategory> lambda = wrapper.lambda();
        if (queryParam.getId() != null) {
            lambda.eq(CmsContentCategory::getId, queryParam.getId());
        }
        if (queryParam.getName() != null) {
            lambda.like(CmsContentCategory::getName, queryParam.getName());
        }
        if (queryParam.getDeleteFlag() != null) {
            lambda.eq(CmsContentCategory::getDeleteFlag, queryParam.getDeleteFlag());
        }
        if (queryParam.getShowStatus() != null) {
            lambda.eq(CmsContentCategory::getShowStatus, queryParam.getShowStatus());
        }
        return page(page, wrapper);
    }
}
